/**
 * Created by Administrator on 2017/11/8/008.
 */
var count=0;//轮询次数
var timer;
function pay(orderId) {
    $.ajax({
        method:"post",
        url:"/order/pay/"+orderId+"/1",
        dataType:"json",
        success:function (result) {
            $("#qrimg").html('<img src="'+result.data+'"/>');
            timer=setInterval("queryOrderPayStatus('"+orderId+"')",4000);//每4秒执行一次订单状态查询
        },
        error:function () {
            $("#qrimg").html('<span style="color:red">支付失败，请稍候尝试</span>');
        }
    });
}

function queryOrderPayStatus(orderId) {
    $.getJSON("/order/query_order_pay_status/"+orderId,function (result) {
        if(result.status == 0){//如果订单已支付
            clearInterval(timer);
            window.location.href="/order/getPayInfo/"+result.data;
        }else{
            //未支付,最多查询10次
            if(count < 10){
                count++;
            }else{
                clearInterval(timer);
                alert("支付失败");
            }
        }
    });
}